package org.devocean.groupbuying.utils;

import org.apache.tiles.AttributeContext;
import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.preparer.ViewPreparer;
import org.devocean.groupbuying.domain.Customer;
import org.devocean.groupbuying.service.CategoryService;
import org.devocean.groupbuying.service.CustomerService;
import org.devocean.groupbuying.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Component;

@Component
public class ExplorerSidebarPreparer implements ViewPreparer {

	@Autowired
	private CategoryService categoryService;

	public void execute(TilesRequestContext requestContext,
			AttributeContext context) {

		String lang = null;
		try {
			lang = requestContext
					.getRequestScope()
					.get("org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE")
					.toString();
		} catch (Exception e) {
			lang = "en";
		}

		requestContext.getRequestScope().put("categories",
				categoryService.getDisplayCategories(lang));

	}
}
